
# -- 函数内部是一个作用域
# set(n 100)
# function(fun)
#     set(n 200 PARENT_SCOPE) # 修改父作用域的变量
#     message("In function, n = ${n}")
# endfunction()

# # Call
# fun()
# message("Out function, n = ${n}")

# message("---------------------------------------------------")

# -- 可变参数
# function(foo arg1 arg2)
#     message(STATUS "${arg1} ${arg2}")
#     message(STATUS "argc = ${ARGC}")
#     message(STATUS "argv = ${ARGV}")
#     message(STATUS "${ARGV0} ${ARGV1}")
#     message(STATUS "${ARGN}") # 匿名参数
# endfunction()

# foo(1 2 3 4)


# -- 带有关键字的参数解析
function(GetSource source libs dir)
    # 解析单值的LIBS,DIR 和 多值的FILES
    cmake_parse_arguments("GetSource" PARSE_ARGV "LIBS;DIR" "FILES" ${ARGV})
    message(STATUS "DIR:${GetSource_DIR} Source:${GetSource_FILES} Libs:${GetSource_LIBS}")
endfunction()

GetSource(FILES main.cpp head.h LIBS libAMath.a DIR "~/Desktop")

function(GetPath platform path)
    # 解析单值的PATH
    cmake_parse_arguments("GetPath" PARSE_ARGV "PATH" "" ${ARGV})
    message(STATUS "Platform:${platform} ${GetPath_PATH}")
endfunction()

GetPath("Windows" PATH "D:/temp")